home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 6.8 KB | 231 lines | [TEXT/KAHL] |
- /***************************************************** IMPLEMENTATION
- DATE: 11/7/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPTreeArea
-
- SUPERCLASS: CPPScrollArea, CPPVisualTree
-
- This C++ class manages a tree which lives inside a scrolling
- area.
-
- ********************************************************************/
-
- #include <CPPTreeArea.h>
- #include <CPPWindow.h>
- #include <ToolboxTools.h>
-
- /*-----------------------------------------------------------------*/
- /*------------------------ APPLY ROUTINES -------------------------*/
- /*-----------------------------------------------------------------*/
-
- extern void SetSelectState (CPPTreeNode *theNode, long param);
-
- void DoRectSelect (CPPTreeNode *theNode, long param)
- /* use the 'modifiers' information passed in 'param' to determine */
- /* how to alter the selection state of the passed in node */
- {
- CPPVisualTreeNode *vNode = (CPPVisualTreeNode *)theNode;
-
- if (vNode)
- {
- if (CommandKeyDown(param))
- vNode->SetSelect(kSetSelect, FALSE, TRUE);
- else
- if (ShiftKeyDown(param))
- vNode->SetSelect(kToggleSelect, FALSE, TRUE);
- else
- vNode->SetSelect(kSetSelect, FALSE, TRUE);
- }
-
- }
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- CPPTreeArea::CPPTreeArea (CPPWindow *OurWindow,
- Rect *ViewArea,
- Rect *DestArea,
- Boolean UseHScroll,
- Boolean UseVScroll,
- short hStep,
- short vStep,
- orientStyle orientation,
- justStyle justification,
- joinTypes join,
- short branchLength) :
- CPPVisualTree (OurWindow->GetWindow(),
- topLeft(*DestArea),
- orientation, justification,
- join, branchLength),
- CPPScrollArea (OurWindow, ViewArea, DestArea,
- UseHScroll, UseVScroll,
- hStep, vStep)
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPTreeArea::CPPTreeArea (CPPWindow *OurWindow,
- Boolean UseHScroll,
- Boolean UseVScroll,
- short hStep,
- short vStep,
- orientStyle orientation,
- justStyle justification,
- joinTypes join,
- short branchLength) :
- CPPVisualTree (OurWindow->GetWindow(),
- topLeft((OurWindow->GetWindow())->portRect),
- orientation, justification,
- join, branchLength),
- CPPScrollArea (OurWindow, UseHScroll, UseVScroll,
- hStep, vStep)
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPTreeArea::~CPPTreeArea (void)
- {
-
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPTreeArea::ClassName (void)
- {
- return "CPPTreeArea";
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPTreeArea::Member (char *className)
- {
- if (strcmp(className, CPPTreeArea::ClassName()) == 0)
- return TRUE;
- else
- if (CPPVisualTree::Member(className))
- return TRUE;
- else
- return CPPScrollArea::Member(className);
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPTreeArea::DoScrollAreaClick (Point clickPt, short modifiers,
- Rect *selRect)
- /* handle a click in the scroll area; clickPt is in area coordinates */
- /* a rectangle encompassing the selected area is returned in selRect */
- /* (this is in area coordinates) */
- /* SUBCLASS SHOULD OVERRIDE */
- {
- Point startPt = clickPt,
- EndPt;
- CPPVisualTreeNode *theNode;
- Boolean wasDoubleClick = FALSE, selState = TRUE;
-
- // first, check to see if the click was in a node
- if (theNode = ((CPPVisualTreeNode *)this->topNode)->PointInNode (clickPt))
- {
- // determine whether we have double-clicked on the node
- wasDoubleClick = (theNode == this->lastClicked) &&
- (TickCount() - this->lastClickTime <= GetDblTime());
- this->lastClicked = theNode;
- this->lastClickTime = TickCount();
-
- if (wasDoubleClick)
- theNode->DoDoubleClick (modifiers);
- else
- { // if the shift key is down, invert selection state
- if (ShiftKeyDown(modifiers))
- theNode->SetSelect(kToggleSelect, FALSE, TRUE);
- else
- // if the command key is down, add to selection
- if (CommandKeyDown (modifiers))
- theNode->SetSelect(kSetSelect, FALSE, TRUE);
- else
- { // if no modifiers down, de-select all and select this one
- ApplyToFamily(this->topNode, SetSelectState, kClearSelect);
- theNode->SetSelect(kSetSelect, FALSE, TRUE);
- }
- theNode->DoSingleClick (modifiers);
- }
- return TRUE;
- }
- else // the user did not click in a node. De-select the current selection
- { // if necessary, then let the user drag-select a new selection
- if (!ShiftKeyDown (modifiers) &&
- !CommandKeyDown(modifiers))
- ApplyToFamily(this->topNode, SetSelectState, kClearSelect);
-
- // default behavior; scroll the area automatically as long
- // as the mouse is down
- if (CPPScrollArea::DoScrollAreaClick(clickPt, modifiers, selRect))
- {
- // hilight all selected nodes
- if (this->topNode)
- ((CPPVisualTreeNode *)this->topNode)->DoOnFamilyInRect (selRect,
- TRUE, DoRectSelect, modifiers);
- return TRUE;
- }
-
- } // PtInRect
-
- return FALSE;
- }
-
- /*-----------------------------------------------------------------*/
-
- Boolean CPPTreeArea::DoCommand (short commandID)
- {
- if (!CPPVisualTree::DoCommand(commandID))
- return CPPScrollArea::DoCommand(commandID);
- else
- return TRUE;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPTreeArea::Draw (void)
- {
- CPPScrollArea::Draw();
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPTreeArea::DrawContents (void)
- {
- this->isPrepared = TRUE;
- this->preparedBy = (CPPVisualTree *)this;
-
- CPPVisualTree::Draw();
-
- this->isPrepared = FALSE;
- this->preparedBy = NULL;
- }
-
-
- /*-----------------------------------------------------------------*/
- /*---------------------- PROTECTED METHODS ------------------------*/
- /*-----------------------------------------------------------------*/
-
- void CPPTreeArea::UserSpecificPrepare (void)
- /* set the origin of the grafport before drawing */
- /* SUBCLASS MAY OVERRIDE */
- {
- AdjustCoordinates();
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPTreeArea::UserSpecificRestore (void)
- /* restore the origin of the grafport after drawing */
- /* SUBCLASS MAY OVERRIDE */
- {
- RestoreCoordinates();
- }
-